package com.frcdi.qms.web.controller.masterdata;

import com.frcdi.qms.common.core.controller.BaseController;
import com.frcdi.qms.common.core.domain.AjaxResult;
import com.frcdi.qms.common.core.page.TableDataInfo;
import com.frcdi.qms.common.utils.poi.ExcelUtil;
import com.frcdi.qms.masterdata.domain.ChangHistory;
import com.frcdi.qms.masterdata.service.IChangHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 变更历史Controller
 *
 * @author cell
 * @date 2024-01-16
 */
@Api(tags = "变更历史")
@RestController
@RequestMapping("/masterData/changHistory")
public class ChangHistoryController extends BaseController
{
    @Autowired
    private IChangHistoryService changHistoryService;

    /**
     * 查询变更历史列表
     */
    @ApiOperation("查询变更历史列表")
//    @PreAuthorize("@ss.hasPermi('masterData:changHistory:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChangHistory changHistory)
    {
        startPage();
        List<ChangHistory> list = changHistoryService.selectChangHistoryList(changHistory);
        return getDataTable(list);
    }

    /**
     * 导出变更历史列表
     */
    @ApiOperation("导出变更历史列表")
    @PreAuthorize("@ss.hasPermi('masterData:changHistory:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChangHistory changHistory)
    {
        List<ChangHistory> list = changHistoryService.selectChangHistoryList(changHistory);
        ExcelUtil<ChangHistory> util = new ExcelUtil<ChangHistory>(ChangHistory.class);
        util.exportExcel(response, list, "变更历史数据");
    }

    /**
     * 获取变更历史详细信息
     */
    @ApiOperation("获取变更历史详细信息")
//    @PreAuthorize("@ss.hasPermi('masterData:changHistory:query')")
    @GetMapping(value = "/{historyId}")
    public AjaxResult getInfo(@PathVariable("historyId") Long historyId)
    {
        return success(changHistoryService.selectChangHistoryByHistoryId(historyId));
    }

    /**
     * 新增变更历史
     */
    @ApiOperation("新增变更历史")
//    @PreAuthorize("@ss.hasPermi('masterData:changHistory:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ChangHistory changHistory)
    {
        changHistory.setCreateBy(getUsername());
        return toAjax(changHistoryService.insertChangHistory(changHistory));
    }

    /**
     * 修改变更历史
     */
    @ApiOperation("修改变更历史")
    @PreAuthorize("@ss.hasPermi('masterData:changHistory:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ChangHistory changHistory)
    {
        return toAjax(changHistoryService.updateChangHistory(changHistory));
    }

    /**
     * 删除变更历史
     */
    @ApiOperation("删除变更历史")
    @PreAuthorize("@ss.hasPermi('masterData:changHistory:remove')")
	@DeleteMapping("/{historyIds}")
    public AjaxResult remove(@PathVariable("historyIds")  Long[] historyIds)
    {
        return toAjax(changHistoryService.deleteChangHistoryByHistoryIds(historyIds));
    }
}
